package net.togogo.egouweb1238.core.service.area.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.togogo.egouweb1238.common.page.Pagination;
import net.togogo.egouweb1238.core.dao.area.TownDao;
import net.togogo.egouweb1238.core.domain.area.Town;
import net.togogo.egouweb1238.core.query.area.TownQuery;
import net.togogo.egouweb1238.core.service.area.ITownService;
/**
 * 县/区
 * @author stone
 */
@Service
@Transactional
public class TownServiceImpl implements ITownService {

	@Resource
	private TownDao townDao;

	/**
	 * 插入数据库
	 * 
	 * @return
	 */
	public Integer addTown(Town town) {
		return townDao.addTown(town);
	}

	/**
	 * 根据主键查找
	 */
	@Transactional(readOnly = true)
	public Town getTownById(Integer id) {
		return townDao.getTownById(id);
	}
	
	@Transactional(readOnly = true)
	public List<Town> getTownsByIds(List<Integer> idList) {
		return townDao.getTownsByIds(idList);
	}

	/**
	 * 根据主键删除
	 * 
	 * @return
	 */
	public Integer deleteById(Integer id) {
		return townDao.deleteById(id);
	}

	public Integer deleteByIds(List<Integer> idList) {
		return townDao.deleteByIds(idList);
	}

	/**
	 * 根据主键更新
	 * 
	 * @return
	 */
	public Integer updateTownById(Town town) {
		return townDao.updateTownById(town);
	}
	
	@Transactional(readOnly = true)
	public Pagination getTownListWithPage(TownQuery townQuery) {
		Pagination p = new Pagination(townQuery.getPageNo(),townQuery.getPageSize(),townDao.getTownListCount(townQuery));
		p.setList(townDao.getTownListWithPage(townQuery));
		return p;
	}
	
	@Transactional(readOnly = true)
	public List<Town> getTownList(TownQuery townQuery) {
		return townDao.getTownList(townQuery);
	}
}
